package com.ynu.springbootappdemo.model.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ynu.springbootappdemo.common.entity.LogicEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
@Where(clause = "is_deleted = 0")
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"})
public class Orders extends LogicEntity {
    // 订单金额
    private Double orderAmount;
    // 订单状态
    @Column(insertable = false,
            nullable = false,
            columnDefinition="INT default 0")
    private Integer orderState; //订单状态（0：未支付； 1：已支付；2：已经确认；3：已退款）
    // 订单备注
    private String orderRemark;
    // 配送时间
    private String deliveryTime;

    @OneToMany(cascade = {CascadeType.MERGE,CascadeType.REMOVE,CascadeType.PERSIST},fetch = FetchType.EAGER)
    @JoinColumn(name = "order_id")
    @JsonIgnoreProperties("order")
    private Set<OrderDetail> orderDetails;

    @ManyToOne(cascade = {CascadeType.MERGE},fetch = FetchType.EAGER)
    @JoinColumn(name = "customer_id")
    @JsonIgnoreProperties("orders")
    private Customer customer;

    // 收货地址
    @OneToOne
    @JoinColumn(name = "deliveryAddress_id", referencedColumnName = "id")
    private DeliveryAddress deliveryAddress;
}
